TOOL.Category   = "Construction"
TOOL.Name       = "#Entity Locator"
TOOL.Command    = nil
TOOL.ConfigName = nil

TOOL.ClientConVar[ "entity" ] 		= 0

if ( SERVER ) then

end

if ( CLIENT ) then 

language.Add("Tool_locatormarker_name", "Entity Locator Tool")
language.Add("Tool_locatormarker_desc", "Adds an entity locator to a contraption")
language.Add("Tool_locatormarker_0", "Left click to add a locator. \nRight click to remove a locator. "--[[\nReload to pick a random skin.]] )

end -- if CLIENT

function TOOL:LeftClick(Trace)
	if( CLIENT ) then return true end

	if not Trace.Entity:IsValid() then
		return false
	end

	if not Trace.Entity:GetClass() == "prop_physics" then
		return false
	end
	
	for _, ent in pairs(constraint.GetAllConstrainedEntities(Trace.Entity)) do
		if ent:GetClass() == "gmod_locator" then
			return false
		end
	end
	
	local ent = ents.Create("gmod_locator")
	ent:SetPos( Trace.HitPos )
	ent:Spawn()
	ent:Activate()
	ent:SetParent(Trace.Entity)
	
	return true

end

function TOOL:Reload(Trace)
    
end

function TOOL:RightClick(Trace)
	if( CLIENT ) then return true end
	
 	if not Trace.Entity:IsValid() then
		return false
	end

	if not Trace.Entity:GetClass() == "prop_physics" then
		return false
	end
	
	for _, ent in pairs(constraint.GetAllConstrainedEntities(Trace.Entity)) do
		if ent:GetClass() == "gmod_locator" then
			ent:Remove()
		end
	end
	return true
end

function TOOL:Think()

end
